class Solution:
    def subdomainVisits(self, cpdomains: List[str]) -> List[str]:
        dic1 = collections.Counter()  #create a dict subclass counter
        ans = []
        for str_i in cpdomains:
            str_i_num, str_i_dom = str_i.split()  #extract count and domain
            str_i_dom_splt = str_i_dom.split(".")
            for dom_j in range(len(str_i_dom_splt)):
                dic1[".".join(str_i_dom_splt[dom_j:])] += int(str_i_num)
        for key, count in dic1.items():
            ans.append("{} {}".format(count, key))
        return ans
